package DocketManage

import (
	"MedicalTreatment/global"
	"MedicalTreatment/model"
	"fmt"
	"github.com/gin-gonic/gin"
)

func NewPhysician(r *gin.Engine) {
	r.POST("/addDocket", func(context *gin.Context) {
		var docket model.Docket
		if err := context.ShouldBindJSON(&docket); err != nil {
			context.JSON(200, gin.H{
				"Msg": err,
			})
		} else {

			if err := global.DB.Create(&docket).Error; err != nil {
				context.JSON(200, gin.H{
					"Msg": err,
				})
			} else {

				var guanxi model.DepDoc
				guanxi = model.DepDoc{
					Doc_id: docket.ID,
					Dep_id: docket.Docket_department,
				}

				if err := global.DB.Create(&guanxi).Error; err != nil {

					context.JSON(200, gin.H{
						"Msg": err,
					})

				} else {
					fmt.Println("111")
					context.JSON(200, gin.H{
						"Msg": "创建成功",
					})
				}

			}
		}
	})

}
